// pages/game/trainingDetails/trainingDetails.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    star: 0.5,
    noteList: [],
    chooseList: [],
    order: null, //订单
  },
  // 提交
  submit() {
    if (!!this.data.order && this.data.chooseList.length > 0 && this.data.star != 0) {
      var obj = {
        orderId: this.data.order.orderId, //	是	int	订单ID
        value: this.data.star, //是	BigDecimal	订单ID
        labelIds: this.data.chooseList, //	是	数组	评价标签id
      }

      var postObj = {
        url: '/manage/client/order/evaluate',
        method: 'PUT',
        data: obj
      }

      app.request.gameRequest(postObj).then(res => {
        console.log('提交', res.data.data)
        wx.showToast({
          title: '评价成功',
          icon: "success",
          duration: 2000,
          success: () => {
            setTimeout(() => {
              wx.navigateBack()
            }, 2000)

          }
        })
      }).catch(err => {})

      console.log(obj);

    } else {
      wx.showToast({
        title: '未填写完整！',
        icon: "none",
        duration: 2000,
      })
    }


  },
  // 监听复选框
  onChangebox(event) {
    this.setData({
      chooseList: event.detail,
    });
    console.log(this.data.chooseList)
  },
  // 监听评星
  onChangestar(event) {
    this.setData({
      star: event.detail,
    });
  },

  clickNode(e) {
    var index = e.currentTarget.dataset.index

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    var orderId = options.orderId
    console.log('orderId', orderId);
    var postObj = {
      url: '/manage/client/order/list/orderDetail',
      method: 'POST',
      data: {
        orderId: orderId
      }
    }
    app.request.gameRequest(postObj).then(res => {
      console.log('查询该订单详情', res.data.data)
      that.setData({
        order: res.data.data
      })
    }).catch(err => {})

    var getObj = {
      url: '/manage/client/label/list',
      method: 'get',
      data: {}
    }
    app.request.gameRequest(getObj).then(res => {
      console.log('标签', res.data.data)
      that.setData({
        noteList: res.data.data
      })
    }).catch(err => {})


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})